// pages/self/appointRecord/appointRecord.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputShowed:"",
      inputTyping:"",
      inputVal:"",
      flag:"0",
    classfiySelect:"",
      doctorId:"",
      fieldid:"",
      rigId:'01',
      leftText: [{
        id: "01",
        office: "已就诊",
      },
      {
        id: "02",
        office: "未就诊",
      },
      ],
      rightData: [{
        id: "01",
        title:"已就诊",
        frist: [/*{
          url: "/pages/images/8.png",
          doctorname: "王医生",
          doctortitle: "特邀专家",
          doctorid:"10",          
          clinicType:'01',
          bookId:'100'
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01'
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"10",
          clinicType:'01',
          times:"2020-12-1"
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01'
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"10",
          clinicType:'01'
        },
        {
          url: "/pages/images/8.png",
          doctorname: "张医生",
          doctortitle: "特邀专家",
          doctorid:"20",
          clinicType:'01'
        }*/
      ],
      },
      {
        id: "02",
        title:"未就诊",
        frist:[],
        /*frist: [
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"10",
            clinicType:'02'
          },
          {
            url: "/pages/images/8.png",
            doctorname: "张医生",
            doctortitle: "特邀专家",
            doctorid:"20",
            clinicType:'02'
          }
        ],*/
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      classfiySelect: this.data.leftText[0].id,
    })
    console.log(getApp().globalData.doctorId)
    this.showMessage();
  },
  showMessage:function()
  {
    var that = this;
    wx.request({
      url:  getApp().globalData.url+'patientmedicalrecord', // 仅为示例，并非真实的接口地址
      method: 'GET',
      data: {
        unitphone:getApp().globalData.unitphone,
        flag:this.data.flag,
        searchText:this.data.inputVal
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success(res) {  
        console.log(res.data)
        let fi={};
        let first=[];
        for(let j=0;j<2;j++)
        {
          for(let i=0;i<res.data.length;i++)
          {
            if(res.data[i].orderForm.progress==that.data.leftText[j].office)
            {
              var doctorId0="";
              var doctorRank0="";
              var doctorName0 ="";
              var photoUrl0="";
              var bookId0 ="";
              var times0="";
              var date0="";
              doctorName0=res.data[i].doctorName;
              doctorId0=res.data[i].orderForm.doctorId;
              doctorRank0=res.data[i].doctorRank;
              photoUrl0=res.data[i].doctorPhoto;
              bookId0=res.data[i].orderForm.bootId;
              times0=res.data[i].orderForm.bootTime;
              date0=res.data[i].orderForm.bootDate;
              fi ={"doctorname":doctorName0,"doctortitle":doctorRank0,"doctorid":doctorId0,"url":photoUrl0,"clinicType":that.data.leftText[j].id,"bookId":bookId0,"times":times0+" "+date0};        
              first.push(fi);
            }
          }
          if(j==0)
          {
            that.setData({
              "rightData[0].frist":first
            })
          }
          else if(j==1)
          {
            that.setData({
              "rightData[1].frist":first
            })
          }  
         first=[];
        }     
      },
      fail(res){
        wx.showToast({
          title: '网络连接失败，请重新尝试',
          icon:'none'
        })
      }
    })
  },
  showInput: function () {
    this.setData({
    inputShowed: true
    });
    },
    hideInput: function () {
    this.setData({
    inputVal: "",
    inputShowed: false
    });
    // getList(this);
    },
    clearInput: function () {
    this.setData({
    inputVal: "",
    flag:0,
    });
    this.showMessage();
    // getList(this);
    },
    inputTyping: function (e) {
    //搜索数据
    // getList(this, e.detail.value);
    this.setData({
    inputVal: e.detail.value,
    flag:1
    });
    console.log(this.data.inputVal);
    this.showMessage();
    },

  scroll: function(e) {
    var scrollTop = e.detail.scrollTop,
    h = 0,
    classfiySelect;
    var that = this;
    that.data.leftText.forEach(function(clssfiy, i) {
      var _h =26 + that.length(clssfiy['id'])*102;
      if (scrollTop >= h){
        classfiySelect = clssfiy['id'];
      }
    h +=_h;
    })
    that.setData({
    classfiySelect: classfiySelect,
    })
    console.log(that.data.classfiySelect)
  },
  //求每一栏高度
  length: function(e) {
    var that = this;
    var rightData = that.data.rightData;
    for (var i = 0; i < rightData.length; i++) {
      if(rightData[i]['id']==e){
        return rightData[i]['frist'].length;
      }
    }
  },
  //点击左边事件
  left_list: function(e) {
    var that = this;
    var l_id = e.currentTarget.dataset.id;
    that.setData({
      rigId: l_id,
    })
  },
  toRecords: function(e){
    var chooseBook = e.target.dataset.index;
    console.log(chooseBook)
    app.globalData.bookId=chooseBook
    console.log(app.globalData.bookId)
    wx.navigateTo({
      url: '../medicalRecords/medicalRecords',
    })
  },
  toAppointment: function(e){
    var chooseBook = e.target.dataset.index;
    console.log(chooseBook)
    app.globalData.bookId=chooseBook
    console.log(app.globalData.bookId)
    wx.navigateTo({
      url: '../appointInformation/appointInformation',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})